package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InvoiceTitle;
import com.ruoyi.system.service.IInvoiceTitleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发票抬头Controller
 * 
 * @author ruoyi
 * @date 2021-06-28
 */
@RestController
@RequestMapping("/system/title")
public class InvoiceTitleController extends BaseController
{
    @Autowired
    private IInvoiceTitleService invoiceTitleService;

    /**
     * 查询发票抬头列表
     */
//    @PreAuthorize("@ss.hasPermi('system:title:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvoiceTitle invoiceTitle)
    {
        startPage();
        List<InvoiceTitle> list = invoiceTitleService.selectInvoiceTitleList(invoiceTitle);
        return getDataTable(list);
    }

    /**
     * 导出发票抬头列表
     */
//    @PreAuthorize("@ss.hasPermi('system:title:export')")
    @Log(title = "发票抬头", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(InvoiceTitle invoiceTitle)
    {
        List<InvoiceTitle> list = invoiceTitleService.selectInvoiceTitleList(invoiceTitle);
        ExcelUtil<InvoiceTitle> util = new ExcelUtil<InvoiceTitle>(InvoiceTitle.class);
        return util.exportExcel(list, "title");
    }

    /**
     * 获取发票抬头详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:title:query')")
    @GetMapping(value = "/{itId}")
    public AjaxResult getInfo(@PathVariable("itId") Long itId)
    {
        return AjaxResult.success(invoiceTitleService.selectInvoiceTitleById(itId));
    }

    /**
     * 新增发票抬头
     */
//    @PreAuthorize("@ss.hasPermi('system:title:add')")
    @Log(title = "发票抬头", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InvoiceTitle invoiceTitle)
    {
        return toAjax(invoiceTitleService.insertInvoiceTitle(invoiceTitle));
    }

    /**
     * 修改发票抬头
     */
//    @PreAuthorize("@ss.hasPermi('system:title:edit')")
    @Log(title = "发票抬头", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvoiceTitle invoiceTitle)
    {
        return toAjax(invoiceTitleService.updateInvoiceTitle(invoiceTitle));
    }

    /**
     * 删除发票抬头
     */
//    @PreAuthorize("@ss.hasPermi('system:title:remove')")
    @Log(title = "发票抬头", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itIds}")
    public AjaxResult remove(@PathVariable Long[] itIds)
    {
        return toAjax(invoiceTitleService.deleteInvoiceTitleByIds(itIds));
    }
}
